from flask import Blueprint,jsonify,request
from db import db1
import datetime
bp_recold = Blueprint('recold',__name__)

@bp_recold.route('/cateM')
def cateM():
    sql = "select * from yptype"
    rse = db1.find_all(sql)
    return jsonify({'code':200,'list':rse})

@bp_recold.route('/recordM')
def recordM():
    id = request.args.get('typeid')
    if id == '0':
        sql = "select * from record"
    else:
        sql = "select * from record where typeid=%d"%(int(id))
    rse = db1.find_all(sql)
    list = []
    for i in rse:
        dict = {'id':i['id'],'stime':datetime.datetime.strftime(i['stime'],'%Y-%m-%d'),'etime':datetime.datetime.strftime(i['etime'],'%Y-%m-%d'),'money':i['money']}
        list.append(dict)
    return jsonify({'code':200,'list':list})
